package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.OrderLine;
import com.briup.jz.service.IOrderLineService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="订单管理相关接口")
@Validated
@RestController
@RequestMapping("/orderLine")
public class OrderLineController {

	@Autowired
	private IOrderLineService orderLineService;
	
	@ApiOperation(value="按id查询订单明细")
	@GetMapping("query")		
	    public Message query(Long id) {
			List<OrderLine> list = orderLineService.query(id);
			return MessageUtil.success(list);
	    }
	
	 @ApiOperation(value = "通过id删除订单明细")
	 @GetMapping("deleteById")
	 @ApiImplicitParams({
	 @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
	    })
	public Message deleteById(@NotNull Long id) {
		orderLineService.deleteById(id);
		return MessageUtil.success("删除成功");
		
	}
	 
	 @ApiOperation(value = "保存或更新订单项")
	    @ApiImplicitParams({
	            @ApiImplicitParam(name="id",value = "订单号",paramType = "form"),
	            @ApiImplicitParam(name="number",value = "产品编号",paramType = "form"),
	            @ApiImplicitParam(name="price",value = "产品价格",paramType = "form"),
	            @ApiImplicitParam(name="productId",value = "产品id",paramType = "form"),
	            @ApiImplicitParam(name="orderId",value = "订单id",paramType = "form"),
	            
	    }) 
	 @PostMapping("saveOrUpdate")
		public Message saveOrUpdate(OrderLine orderLine) {
			orderLineService.saveOrUpdate(orderLine);
			return MessageUtil.success("更新成功");
			
		}
}
